/*
 *  Button
 *  created by qinghong
 *  2016-7-13
 */

/*
 * 定制版button,需给定参数  style, normalImg, selectedImg, pressAction
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity
} from 'react-native';

export default class Button extends Component {
    constructor(props) {
        super(props);
        this.state = {
            selected: false
        };
    }

    btnAction = () => {
        this.setState({
            selected: !this.state.selected
        });
        const { pressAction } = this.props;
        pressAction();
    };

    render() {
        const { style, normalImg, selectedImg } = this.props;

        return (
            <TouchableOpacity style={style} onPress={this.btnAction}>
                <Image source={this.state.selected ? selectedImg : normalImg}/>
            </TouchableOpacity>
        );
    }
}

